package com.demo.bookstore.dao.impl;

import com.demo.bookstore.bean.BookOrder;
import com.demo.bookstore.dao.OrderDao;

import java.util.List;

/**
 * @author ddone
 * @date 2024/3/17-11:03
 */
public class OrderDaoImpl extends BaseDaoImpl implements OrderDao {
    @Override
    public void addOrder(BookOrder bookOrder) {
        String sql = "insert into book_order(order_no,user_id,total_amount,total_count, order_status,create_time)" +
                " values(?,?,?,?,?,?)";
        this.update(sql,bookOrder.getOrderNo(),bookOrder.getUserId(),
                  bookOrder.getTotalAmount(),bookOrder.getTotalCount(),
                bookOrder.getOrderStatus(),bookOrder.getCreateTime()
                );
    }

    @Override
    public int findOrderId(String orderNo) {
        String sql = "select order_id from book_order where order_no=?";
        return  Integer.parseInt(this.getValue(sql,orderNo).toString());
    }

    @Override
    public List<BookOrder> findOrderByUserId(int userId) {
        String sql = "select order_id orderId,order_no orderNo, create_time createTime," +
                "total_count totalCount, total_amount totalAmount,order_status orderStatus,user_id UserId from book_order " +
                "where user_id=?";
        return this.getList(BookOrder.class,sql,userId);
    }

}
